﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using ATSIDAL;
using ATSModel;
using ATSModel.T_ReportInfo;

namespace ATSDAL
{
    public class PIMReport : BaseRepository<PIMReportInfo>, IPIMReport
    {
        private const string PARM_TESTITEM_STRATDATE = "@starttime";
        private const string PARM_TESTITEM_ENDDATE = "@stoptime";
        private const string PARM_TESTITEM_PRODUCTSN = "@productSN";

        public IList<PIMReportInfo> LoadEntities()
        {
            return null;
        }

        public PIMReportInfo LoadEntity<T1>(T1 Id)
        {
            return null;
        }

        public IList<PIMReportInfo> GetPIMDataByDate(DateTime StartDate, DateTime EndDate)
        {
            SqlParameter[] testItemParms = GetSNTParameters();
            //Bind the parameter
            testItemParms[0].Value = StartDate;
            testItemParms[1].Value = EndDate;
            return ExcuteSqlToGetEntities("PIMTest_Data_DT", testItemParms);
        }

        public IList<PIMReportInfo> GetPIMData()
        {
            return ExcuteSqlToGetEntities("PIMTest_Date_All");
        }


        public IList<PIMReportInfo> GetProductSN(string productSN)
        {
            SqlParameter parm = new SqlParameter(PARM_TESTITEM_PRODUCTSN, SqlDbType.NVarChar, 50);
            parm.Value = productSN;
            return ExcuteSqlToGetEntities("PIMTest_Data_ProductSN", parm);
        } 

        #region 参数部分
        private static SqlParameter[] GetSNTParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TESTITEM_STRATDATE, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TESTITEM_ENDDATE, SqlDbType.DateTime, 8)                
                };
            return parms;
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override PIMReportInfo GetEntityRecord(SqlDataReader rdr)
        {
            PIMReportInfo pro = new PIMReportInfo
            {
                RecordDate = rdr.GetValue(0).ToString(),
                ShiftClass = rdr.GetValue(1).ToString(),
                MOID = rdr.GetValue(2).ToString(),
                PIMTestStep = rdr.GetValue(3).ToString(),
                ProductTypeName = rdr.GetValue(4).ToString(),
                ProductTypeID = rdr.GetValue(5).ToString(),
                PIMLimite = rdr.GetDouble(6),
                TestCout = rdr.GetInt32(7),
                A = rdr.GetInt32(8),
                B = rdr.GetInt32(9),
                C = rdr.GetInt32(10),
                D = rdr.GetInt32(11),
                E = rdr.GetInt32(12),
                //F = rdr.GetInt32(13),
                //G = rdr.GetInt32(14),
                //H = rdr.GetInt32(15),
                //I = rdr.GetInt32(16),
                //J = rdr.GetInt32(17),
                //K = rdr.GetInt32(18),
                FailAmount = rdr.GetInt32(13),
                PassRate = rdr.GetValue(14).ToString(),
                ProductTypeSerialID = rdr.GetValue(15).ToString(),
                User = rdr.GetValue(16).ToString()
            };
            return pro;
        } 
     
        #endregion
    }
}

